home *** CD-ROM | disk | FTP | other *** search
/ The 640 MEG Shareware Studio 2 / The 640 Meg Shareware Studio CD-ROM Volume II (Data Express)(1993).ISO / clang / tc_btree.zip / BTREE.C < prev    next >
C/C++ Source or Header  |  1989-02-05  |  2KB  |  90 lines

  1. #include <stdio.h>
  2. #include <dos.h>
  3. #include "cstruct.h"
  4. #include "datatype.h"
  5. #include "access.h"
  6. #include "btutil.h"
  7. #include "btreeinc.h"
  8.  
  9. #define     MAIN
  10. #include    "globals.h"
  11.  
  12. main(int argc, char * argv[])
  13. {
  14.     tapage * getapage(indexfile *, int);
  15.  
  16.     char    ch;
  17.     int     seed;
  18.     char    datfile[32], nnxfile[32], cnxfile[32];
  19.  
  20.     if (argc < 2) {
  21.         printf("Syntax: btree filename [seed]\n");
  22.         exit (0);
  23.     }
  24.  
  25.     strcpy(datfile, argv[1]);
  26.     strcat(datfile, ".dat");
  27.     strcpy(cnxfile, argv[1]);
  28.     strcat(cnxfile, ".ixc");
  29.     strcpy(nnxfile, argv[1]);
  30.     strcat(nnxfile, ".ixn");
  31.  
  32.     seed = (argc > 2) ? atoi(argv[2]) : 1;
  33.     srand(seed);
  34.  
  35.     clearwindow(1,1, 80,25);
  36.     initindex();
  37.     initkeyboard();
  38.  
  39.     if ( (datfp = openfile (datfile)) == NULL ) {
  40.         ch = select("Data files missing. Create new files (y/n)", "YyNn");
  41.         if (toupper(ch) == 'Y') {
  42.             datfp = makefile( datfile, MAXDATARECSIZE);
  43.             cnxfp = makeindex(cnxfile, 15, 0);
  44.             nnxfp = makeindex(nnxfile, 25, 1);
  45.         }
  46.         else {
  47.             clearwindow(1,1, 80,25);
  48.             exit (0);
  49.         }
  50.     }
  51.     else if ( (cnxfp = openindex(cnxfile)) == NULL ||
  52.               (nnxfp = openindex(nnxfile)) == NULL ) {
  53.  
  54.         ch = select("Index files missing. Reconstruct indice? (y/n) ", "YyNn");
  55.         if (toupper(ch) == 'Y') {
  56.  
  57.             cnxfp = makeindex(cnxfile, 15, 0);
  58.             nnxfp = makeindex(nnxfile, 25, 1);
  59.  
  60.             reconstruct();
  61.  
  62.             select("Index files reconstruction completed. <Return> to continue", "\x0d");
  63.         }
  64.         else {
  65.             clearwindow(1,1, 80,25);
  66.             exit (0);
  67.         }
  68.     }
  69.  
  70.     do {
  71.         update_record_count();
  72.         clearwindow(1,4, 80,21);
  73.         ch = select("Select : U)pdate, C)reate, D)elete, L)ist, Q)uit",
  74.                                                           "ucdlqUCDLQ");
  75.         if ((ch = toupper(ch)) == 'L')
  76.             list();
  77.         else if (ch == 'D')
  78.             delete();
  79.         else if (ch == 'C')
  80.             create();
  81.         else if (ch == 'U')
  82.             update();
  83.     } while (ch != 'Q');
  84.  
  85.     closeindex(nnxfp);
  86.     closeindex(cnxfp);
  87.     closefile(datfp);
  88.  
  89.     clearwindow(1,1, 80,25);
  90. }